package com.cloudfun.campusshare.device.protocol.constant;

import lombok.extern.slf4j.Slf4j;

/**
 * @author wangxiyuan
 * @description 液体泵 工作状态
 * @createDate 2021/5/19 9:45
 **/
@Slf4j
public enum PumpWorkStatus {
    NOT_RUNNING(1,"未启动"),
    //WAIT_RUNNING(2,"等待启动"),
    RUNNING(2,"工作"),
    //RUNNING_OVER(4,"工作结束"),
    ABNORMAL(3,"故障");

    private int status;

    private String desc;

    PumpWorkStatus(int status,String desc){
        this.status = status;
        this.desc = desc;
    }

    public int getStatus() {
        return status;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 状态不需要那么细致，0是未启动 1是启动中 2是故障
     * 根据不同命令类型构建不同的设备状态
     * @param cmdType 命令类型 1,2，3,4,5,6,7
     * @param resStatus 0,1,2
     * @return
     */
    @Deprecated
    public static int getStatus(byte cmdType,byte resStatus){
        if(cmdType == PumpCmdType.DELAY_WORK.getCmdType() || cmdType == PumpCmdType.WORK.getCmdType()){
            // 命令设置成功
            if(resStatus == 1 && cmdType == PumpCmdType.DELAY_WORK.getCmdType()){
                return PumpWorkStatus.RUNNING.status;
            }else if(resStatus == 1 && cmdType == PumpCmdType.WORK.getCmdType()){
                return PumpWorkStatus.RUNNING.status;
            }else if(resStatus == 0){
                // 当响应结果为0时，表示命令未执行成功
                return PumpWorkStatus.NOT_RUNNING.status;
            }
        }
        if(cmdType == PumpCmdType.FIRST_PUMP_REPORT.getCmdType()
                || cmdType == PumpCmdType.SECOND_PUMP_REPORT.getCmdType()
                || cmdType == PumpCmdType.THIRD_PUMP_REPORT.getCmdType()
                || cmdType == PumpCmdType.GET_STATUS.getCmdType()){
            if(resStatus == 1){
                if(cmdType == PumpCmdType.GET_STATUS.getCmdType()){
                    return PumpWorkStatus.RUNNING.status;
                }
                return PumpWorkStatus.NOT_RUNNING.status;
            }else if(resStatus == 2){
                return PumpWorkStatus.ABNORMAL.status;
            }else if(resStatus == 0){
                // 只有命令=2时，查询设备状态，才会返回设备状态为0的信息，表示未启动
                return PumpWorkStatus.NOT_RUNNING.status;
            }
        }
        log.info("命令类型为{}，响应状态为{}",cmdType,resStatus);
        return PumpWorkStatus.NOT_RUNNING.status;
    }

    public static int getPumpStatus(byte cmdType,byte resStatus){
        if(resStatus == 0){
            // 当响应结果为0时，表示命令未执行成功
            return PumpWorkStatus.NOT_RUNNING.status;
        }else  if(resStatus == 1){
            if(cmdType == PumpCmdType.GET_STATUS.getCmdType()){
                return PumpWorkStatus.RUNNING.status;
            }
            return PumpWorkStatus.NOT_RUNNING.status;
        }else if(resStatus == 2){
            return PumpWorkStatus.ABNORMAL.status;
        }
        log.info("命令类型为{}，响应状态为{}",cmdType,resStatus);
        return PumpWorkStatus.NOT_RUNNING.status;
    }

}
